package com.base.msg.presenter;

import android.app.Activity;

import com.base.commonlib.base.presenter.BasePresenter;
import com.base.commonlib.http.RealNetWorkUtil;
import com.base.commonlib.http.utils.CallBackImpl;
import com.base.msg.bean.MsgReadBean;
import com.base.msg.view.MsgReadView;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.disposables.Disposable;

/**
 * Created by weikailiang on 2020/3/13.
 */

public class MsgReadPresenter extends BasePresenter<MsgReadView>{
    public MsgReadPresenter(MsgReadView view, Activity activity) {
        super(view, activity);
    }
    public void getTodoList(int pageIndex, int handle, final boolean isrefresh,int isDelete,int isRead){
        //初始化控件
        Map<String,Object> map = new HashMap<>();
        map.put("page",pageIndex);
        map.put("limit",10);
        map.put("isRead",isRead);
        map.put("isDelete",isDelete);
        map.put("isHandle",handle);//0未处理 1 已处理

        Disposable disposable = RealNetWorkUtil.postContent()
                .method("api-todo/todo/getList")
                .content(map)
                .build().enqueue(MsgReadBean.class, new CallBackImpl<MsgReadBean>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.returnError();
                    }

                    @Override
                    public void onNext(MsgReadBean bean) {
                        if (bean == null){
                            if (isrefresh){
                                mView.returnRefreshNoData();
                            }else {
                                mView.returnLoadMoreNoData();
                            }
                            return;
                        }
                        if (isrefresh){
                            if (bean.getRows()!=null&&bean.getRows().size()>0){
                                mView.returnRefreshList(bean.getRows());
                            }else {
                                mView.returnRefreshNoData();
                            }
                        }else {
                            if (bean.getRows()!=null&&bean.getRows().size()>0){
                                mView.returnLoadMoreList(bean.getRows());
                            }else {
                                mView.returnLoadMoreNoData();
                            }
                        }
                    }
                });
        mCompositeDisposable.add(disposable);
    }
}
